package com.jdrx.sw.sewage.dao;

import com.jdrx.sw.sewage.beans.dto.MaintenanceRecordDTO;
import com.jdrx.sw.sewage.beans.dto.UserMaintenanceDTO;
import com.jdrx.sw.sewage.beans.entity.WorkOrderPO;
import com.jdrx.sw.sewage.beans.vo.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface WorkOrderDAO {

    List<MaintenanceDevVO> findMaintenanceDevList();

    List<MaintenanceDevVO> findTodayNoDo(@Param("currUserId") Long currUserId, @Param("today") Integer today);

    Integer countTodayNoDo(@Param("currUserId") Long currUserId, @Param("today") Integer today);

    void add(Map<String, Object> maps);

    void update(WorkOrderPO workOrderPO);

    List<MaintenanceRecordVO> findMaintenanceRecordList(MaintenanceRecordDTO dto);

    List<MaintenanceRecordVO> findMaintenanceRecordLists(@Param("type") Integer type, @Param("devId") Long devId);

    List<FactoryPeriodsVO> findFactoryPeriods();

    MaintenanceRecordInfoVO findMaintenanceRecordInfo(@Param("id") Long id);

    List<MaintenanceDevVO> findUserMaintenance(UserMaintenanceDTO userMaintenanceDTO);

    Integer countUserMaintenance(@Param("maintenanceById") Long maintenanceById, @Param("maintenanceTime") String maintenanceTime);

    List<ProcessunitVO2> findProcessunitByFp(@Param("factoryPeriod") String factoryPeriod);

    List<CategoryVO> findCategoryByPid(@Param("pId") Long pId);

    List<MaintenanceDevVO> finMaintenanceDevByFp(@Param("factoryPeriods") String factoryPeriods,
                                                 @Param("processunitId") Long processunitId,
                                                 @Param("categoryId") Long categoryId);

    WorkOrderPO findIsNot(@Param("devId") Long devId,
                          @Param("type") Integer type);
    
    /**统计已保养设备数量*/
    int countByAlreadyMaintenance();
    
    /**统计即将保养设备数量*/
    int countByUpcomingMaintenance();
    
    /**统计已过期保养设备数量*/
    int countByExpireMaintenance();
    
    /**统计设备备件分布情况*/
    List<DeviceSpareAnalysisVO> spareAnalysis();
    
    /**
     * 按设备/月统计故障次数，条件为[告警开始时间start_time]
     * @param startTime 查询开始时间
     * @param endTime 查询结束时间
     * @return
     */
    List<DeviceFailureVO> failureAnalysis(@Param("startTime")LocalDateTime startTime, @Param("endTime")LocalDateTime endTime);
    
    /**
     * 按点位、设备统计累计运行时间
     * @param startCollectTime
     * @param endCollectTime
     * @return
     */
    List<DeviceRunTimeVO> runTimeAnalysis(@Param("startCollectTime")LocalDateTime startCollectTime, @Param("endCollectTime")LocalDateTime endCollectTime);
    
    /**
     * 设备累计运行时长top10
     * @return
     */
    List<DeviceRunTimeAnalysisVO> findLJYXSJByTop10();
    
    /**查询库存数量*/
    int countByUnused();
    
    /**查询设备故障总次数*/
    int countByFailure();

    /**
     * 查询最大连续运行时间
     */
    Double maxContinueRunTime();

    /**
     * 查询运行设备数
     */
    int countByCurrentRunDevice(@Param("startCollectTime") LocalDateTime startCollectTime, @Param("endCollectTime") LocalDateTime endCollectTime);

    /**
     * 查询电器设备数
     */
    int countByElectricalDevice();

    Integer countAll();

    WorkOrderPO findById(@Param("id") Long id);
}